﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.components {
    import flash.events.*;
    import reprise.commands.*;
    import flash.display.*;
    import reprise.utils.*;
    import net.wooga.pets.utils.*;

    public class HiddenBirdDisplay extends Sprite {

        private var _hiddenBird:MovieClip;
        private var _animationLabels:Array;
        private var m_delayTimer:TimerCommand;
        private var _clicked:Boolean;

        public function HiddenBirdDisplay(){
            this._animationLabels = ["Giggle", "Wave"];
            super();
            this.createChildren();
        }
        public function remove():void{
            this.killTimer();
            this._hiddenBird.removeEventListener(MouseEvent.MOUSE_OVER, this.hiddenBird_mouseOver);
            this._hiddenBird.removeEventListener(MouseEvent.MOUSE_OUT, this.hiddenBird_mouseOut);
            this._hiddenBird.removeEventListener(MouseEvent.CLICK, this.hiddenBird_click);
            this._hiddenBird.removeEventListener(Event.EXIT_FRAME, this.hiddenBird_frameConstructed);
            this._hiddenBird.removeEventListener(Event.ENTER_FRAME, this.hiddenBird_enterFrame);
            this._hiddenBird = null;
            parent.removeChild(this);
        }
        private function createChildren():void{
            this._hiddenBird = MovieClip(AssetsLibrary.getMovieClip("HiddenBird"));
            this._hiddenBird.buttonMode = true;
            this._hiddenBird.stop();
            this._hiddenBird.mouseChildren = false;
            addChild(this._hiddenBird);
            this._hiddenBird.addEventListener(MouseEvent.MOUSE_OVER, this.hiddenBird_mouseOver);
            this._hiddenBird.addEventListener(MouseEvent.MOUSE_OUT, this.hiddenBird_mouseOut);
            this._hiddenBird.addEventListener(MouseEvent.CLICK, this.hiddenBird_click);
            this.initRandomAnimation();
        }
        private function killTimer():void{
            if (this.m_delayTimer){
                this.m_delayTimer.reset();
                this.m_delayTimer.removeEventListener(Event.COMPLETE, this.delay_complete);
                this.m_delayTimer = null;
            };
        }
        private function initRandomAnimation():void{
            var _local1:int = (5000 + (5000 * Math.random()));
            this.m_delayTimer = new TimerCommand(_local1);
            this.m_delayTimer.addEventListener(Event.COMPLETE, this.delay_complete);
            this.m_delayTimer.execute();
        }
        private function delay_complete(_arg1:Event):void{
            var _local2:int = MathUtil.randomBetween(0, 1);
            this._hiddenBird.gotoAndStop(this._animationLabels[_local2]);
            this._hiddenBird.addEventListener(Event.EXIT_FRAME, this.hiddenBird_frameConstructed);
        }
        private function hiddenBird_click(_arg1:MouseEvent):void{
            this._clicked = true;
            this._hiddenBird.removeEventListener(MouseEvent.MOUSE_OVER, this.hiddenBird_mouseOver);
            this._hiddenBird.removeEventListener(MouseEvent.MOUSE_OUT, this.hiddenBird_mouseOut);
            this._hiddenBird.removeEventListener(MouseEvent.CLICK, this.hiddenBird_click);
            this._hiddenBird.removeEventListener(Event.FRAME_CONSTRUCTED, this.hiddenBird_frameConstructed);
            this._hiddenBird.gotoAndStop("Disappear");
            this._hiddenBird.addEventListener(Event.EXIT_FRAME, this.hiddenBird_frameConstructed);
        }
        private function hiddenBird_frameConstructed(_arg1:Event):void{
            this.killTimer();
            var _local2:MovieClip = MovieClip(this._hiddenBird.animation);
            this._hiddenBird.removeEventListener(Event.EXIT_FRAME, this.hiddenBird_frameConstructed);
            this._hiddenBird.addEventListener(Event.ENTER_FRAME, this.hiddenBird_enterFrame);
            _local2.gotoAndPlay(2);
        }
        private function hiddenBird_enterFrame(_arg1:Event):void{
            var _local2:MovieClip = MovieClip(this._hiddenBird.animation);
            if (((_local2) && ((_local2.currentLabel == "end")))){
                this._hiddenBird.gotoAndStop("default");
                this._hiddenBird.removeEventListener(Event.ENTER_FRAME, this.hiddenBird_enterFrame);
                if (!this._clicked){
                    this.initRandomAnimation();
                } else {
                    removeChild(this._hiddenBird);
                };
            };
        }
        private function hiddenBird_mouseOut(_arg1:MouseEvent):void{
            this._hiddenBird.gotoAndStop("default");
            this.initRandomAnimation();
        }
        private function hiddenBird_mouseOver(_arg1:MouseEvent):void{
            this.killTimer();
            this._hiddenBird.removeEventListener(Event.ENTER_FRAME, this.hiddenBird_enterFrame);
            this._hiddenBird.gotoAndStop("hover");
        }
        public function get hiddenBird():MovieClip{
            return (this._hiddenBird);
        }

    }
}//package net.wooga.pets.views.components 
